from aip import AipOcr
class ImageRecognition:
    # 初始化path，定义为字符类型
    def __init__(self, path: ''):
        self.path = path
    # 你的 APPID AK SK
    APP_ID = '123456'
    API_KEY = 'fydhafbuebfuebiufwbiufe'
    SECRET_KEY = 'difwebfubweufbweffefefefefefef'
    client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
    # 配置参数，识别到图片内容时，需要输出的内容
    def get_garameter(self):
        options = {
            # 识别语言类型，默认为CHN_ENG
            "language_type": "ENG",
            # 是否检测图像朝向，默认不检测，即：false
            "detect_language": "true"
            # 是否返回识别结果中每一行的置信度
            # "probability": "true"
        }
        return options

    # 打开文件
    def get_file_content(self, file_path):
        with open(file_path, 'rb') as fp:
            return fp.read()

    # 需要识别的图片的路径
    def get_image(self):
        return self.get_file_content(self.path)

    # 调用百度ocr接口，进行精准识别
    def ocr(self):
        image_content = self.client.basicAccurate(self.get_image()), self.get_garameter()
        return image_content